//
//  XDHomeViewController.m
//  testDownloadDemo
//
//  Created by XDWY on 2018/3/21.
//  Copyright © 2018年 XDWY. All rights reserved.
//

#import "XDHomeViewController.h"

#import "SelVideoPlayer.h"
#import "SelPlayerConfiguration.h"
#import "AppDelegate.h"
#import "XDVideoPlayerViewController.h"
#import "HSDownloadManager.h"

// 网络视频播放
#define kNetVideoUrl @"http://120.25.226.186:32812/resources/videos/minion_01.mp4"

// 网络视频保存本地后播放
#define kVideoUrlLocal @"http://120.25.226.186:32812/resources/videos/minion_03.mp4"

@interface XDHomeViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) SelVideoPlayer *player;

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataArr;


@end

@implementation XDHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor =[UIColor redColor];
    self.tableView.backgroundColor =[UIColor redColor];
    
    self.tableView.frame =CGRectMake(0, kSmallHeightY, SCREEN_WIDTH, kSmallHeight);
    [self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellId =@"cellId";
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {

        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];

        cell.textLabel.text =self.dataArr[indexPath.row];
        cell.detailTextLabel.text =@"✌️";
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.dataArr.count >indexPath.row) {
        XDVideoPlayerViewController *videoVC =[[XDVideoPlayerViewController alloc]init];
        if (indexPath.row == 0) {
            videoVC.isLocal =NO;
            videoVC.playUrl =kNetVideoUrl;
            [self.navigationController pushViewController:videoVC animated:YES];
            
        }else {
            NSString *url = [[HSDownloadManager sharedInstance]getLocalUrl:kVideoUrlLocal];
            if (url.length) {
                videoVC.isLocal =YES;
                videoVC.playUrl =url;
                [self.navigationController pushViewController:videoVC animated:YES];

            }else {
                [DisplayHelper displayWarningAlert:@"本地没有缓存视频哦！"];
            }
        }
    }
}

#pragma mark - Setter & Getter
-(NSMutableArray *)dataArr {
    if (!_dataArr) {
        _dataArr =[NSMutableArray arrayWithArray:@[@"网络视频播放",@"本地视频播放"]];
    }
    return _dataArr;
}
-(UITableView *)tableView {
    if (!_tableView) {
        _tableView =[[UITableView alloc]init];
        _tableView.delegate =self;
        _tableView.dataSource=self;
    }
    return _tableView;
}

#pragma mark - 子类继承

-(CMNavType)getNavType {
    return CMNavTypeAll;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
